//PersonTest.java
package com.ylaihui.oop8;

public class PersonTest {
	public static void main(String[] args) {
		Person p = new Man();
		
		Man m = (Man)p;
		m.smooking();
		
		// java.lang.ClassCastException
//		Women w = (Women)p;
//		w.goShop();
		
		// 为了解决以上异常， 使用 instanceof 判断
		if(p instanceof Man) {
			Man m1 = (Man)p;
			m.smooking();
		}
		if(p instanceof Women) {
			Women w1 = (Women)p;
			w1.goShop();
		}
		if(p instanceof Person) {
			System.out.println("p is Person");
		}
		if(p instanceof Object) {
			System.out.println("p is Object");
		}
	}
}
